<template>
    <div>
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" inline label-width="80px" size="small">
                <el-form-item label="商品spu" prop="spu">
                    <el-input v-model.trim="queryParams.spu" placeholder="请输入商品spu" clearable style="width: 200px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="页面类型" prop="page_type">
                    <el-select v-model="queryParams.page_type" placeholder="请选择店铺" clearable style="width: 200px">
                        <el-option v-for="(dict, index) in pageTypeList" :key="index" :label="dict.label" :value="dict.label" />
                    </el-select>
                </el-form-item>
                <el-form-item label="创建时间" prop="create_time">
                    <el-date-picker v-model="queryParams.create_time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 240px">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
            </el-form>
        </div>

        <div class="card">
            <el-row :gutter="10" class="mb8">
                <el-col :span="1.5">
                    <el-button size="small" type="primary" plain icon="el-icon-add" @click="showDetailDialog({}, 'add')">新增</el-button>
                </el-col>
                <right-toolbar size="small" :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table v-loading="loading" :data="tableData" row-key="id" border script>
                <el-table-column label="店铺" prop="shop_name" min-width="140" show-overflow-tooltip></el-table-column>
                <el-table-column label="页面类型" prop="page_type" min-width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="商品spu" prop="spu" min-width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="页面路径" prop="page_path" min-width="180" show-overflow-tooltip>
                    <template slot-scope="scope">
                        <span v-if="!scope.row.product_url">{{ scope.row.page_path }}</span>
                        <el-link v-else type="primary" :underline="false" @click="toNewPage(scope.row)">{{ scope.row.page_path }}</el-link>
                    </template>
                </el-table-column>
                <el-table-column label="运营" prop="admin_name" min-width="120" show-overflow-tooltip></el-table-column>
                <el-table-column label="创建时间" prop="create_time" min-width="160"></el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        </div>
        <detail-dialog v-model="detailDialog.visible" v-if="detailDialog.visible" :params="detailDialog.data" :pageTypeList="pageTypeList" @success="handleQuery"></detail-dialog>
    </div>
</template>
<script>
import { get_page_type } from '@/api/report'
import { getPagePathNew } from '@/api/orderReportDataScreen'
import DetailDialog from '@/views/reporting/reportVisitPage/components/DetailDialog.vue'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'ReportVisitListComponent',
    components: { DetailDialog },
    data() {
        return {
            // 遮罩层
            loading: true,
            download: false,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            pageTypeList: [],
            // data中定义Arr数组，用来存放筛选列
            orderArray: [],
            sorts: [], // 用于存储多列排序信息的数组
            create_time: '',
            pageInfo: {
                page: 1,
                limit: 10,
            },
            // 查询参数
            queryParams: {
                spu: undefined,
                page_type: undefined,
                create_time: [],
            },
            detailDialog: {
                visible: false,
                data: {},
            },
        }
    },

    async created() {
        this.loading = true
        try {
            const pageTypeResult = await get_page_type()
            this.pageTypeList = pageTypeResult?.data ?? []
        } catch (error) {
            this.loading = false
            console.log(error)
        }
        this.getList()
    },
    methods: {
        toNewPage(row) {
            const url = row.product_url
            if (url) {
                window.open(url, '_blank')
            }
        },
        showDetailDialog(row) {
            this.detailDialog.visible = true
            this.detailDialog.data = row
        },
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            if (qyparams.create_time?.length == 2) {
                qyparams.create_time = [parseTime(qyparams.create_time[0], 'y-m-d'), parseTime(qyparams.create_time[1], 'y-m-d')]
            }
            getPagePathNew(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    this.total = response.data.total
                })
                .finally(() => {
                    this.loading = false
                })
        },

        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
    },
}
</script>
<style lang="scss" scoped></style>
